package com.ocean.redisson.分布式对象;

import com.ocean.redisson.domain.User;
import org.redisson.api.RBitSet;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @className: RBucketStudy
 * @description: 对象桶（Object Bucket）、二进制流（Binary Stream）、地理空间对象桶（Geospatial Bucket）、
 * BitSet、原子整长形（AtomicLong）、原子双精度浮点数（AtomicDouble）、话题（订阅分发）、
 * 模糊话题、布隆过滤器（Bloom Filter）、基数估计算法（HyperLogLog）
 * @author: lxq
 * @date: 2021/8/8
 **/
@Service
public class RBucketStudy {
    @Autowired
    private RedissonClient redisson;

    public void testObject(){
        RBucket<User> userRBucket = redisson.getBucket("userRBucket");
        User user = new User();
        user.setUsername("111");
        user.setPassword("111");
        userRBucket.set(user);
        User user1 = userRBucket.get();
        System.out.println(user1);
        System.out.println(userRBucket.trySet(new User("222", "222")));
        System.out.println(userRBucket.compareAndSet(new User("222", "222"), new User("333", "333")));
        System.out.println(userRBucket.getAndSet(new User("444", "444")));
    }

    public void testBitSet(){
        RBitSet rBitSet= redisson.getBitSet("simpleBitset");
        rBitSet.set(0,true);
        rBitSet.set(1912,false);
        rBitSet.clear(0);
        rBitSet.xor("anotherBitset");
    }

}
